import {Component, Input, OnInit} from '@angular/core';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {BakeBeanSort} from "../../../../model/BakeBeanSort";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-beansortedit',
  templateUrl: './beansortedit.component.html',
  styleUrls: ['./beansortedit.component.css']
})
export class BeansorteditComponent implements OnInit {
  @Input() id:string;
  b:BakeBeanSort
  fjyArray:Array<any>
  zjyArray:Array<any>
  constructor( private adminService:AdminService,private alertService:AlertService,
               private authService:AuthService) {
    this.b = new BakeBeanSort()
    this.fjyArray = new Array()
    this.zjyArray = new Array()
  }

  ngOnInit(): void {
    this.getBakeBeanSortByid()
    this.getfjyArray()
    this.getzjyArray()


  }

  getBakeBeanSortByid(){
    this.adminService.getEncapsortByid(this.id).then((data:any)=>{
      if(data.msg == "ok"){
        this.b = data.obj
      }else{
        this.alertService.showError("根据id获取分拣失败")
      }
    })
  }


  save(){
    this.adminService.saveEncapsort(this.b).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("设置分拣成功")
      }else{
        this.alertService.showError("设置分拣失败")
      }
    })
  }

  getfjyArray(){
    this.authService.getMemberListByRole("a80fe628162c4db1a5f3af0d9e312a80").then((data:any)=>{
      if(data.msg == "ok"){
        this.fjyArray = data.list
      }else{
        this.alertService.showError("获取分拣员数组失败")
      }
    })
  }
  getzjyArray(){
    this.authService.getMemberListByRole("a80fe628162c4db1a5f3af0d9e312a80").then((data:any)=>{
      if(data.msg == "ok"){
        this.zjyArray = data.list
      }else{
        this.alertService.showError("获取质检员数组失败")
      }
    })
  }

}
